Thumb

Output Parameters in a Stored Procedure

9/14/2020 7:16:56 AM

Output Parameters in a Stored Procedure: The Output Parameters return the initialize value by the stored procedure. We can see the create variable without out or output perematar this called input variable but when we create output variable then we specify the out or output keyword for the variable and initialize the output variable by what value we want to get under output variable and print the value. Now given bellow the example code:

/*CREATE PROCEDURE*/
CREATE PROCEDURE GetDataByPeraOutputPassGendar
@Gendar nvarchar(250),
@EmpCount int out
AS
BEGIN
select @EmpCount= COUNT(Id) from Salary where Gendar=@Gendar
END
/* data with out*/

Declare @EmpTotalByGender int
EXEC GetDataByPeraOutputPassGendar 'Male', @EmpTotalByGender Output
print @EmpTotalByGender

In this code we create a Stord procedure name as ‘GetDataByPeraOutputPassGendar’ and it have two variable one is input and another is output. When we initialize the output variable by our expecting value then we receive the value and print the value from the perematar using print keyword.